using System;
using System.Globalization;
using Windows.UI.Xaml.Data;

namespace WinRTConverters.Format
{
    public class IntToMonthStringCultureConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            try
            {
                if (value != null)
                {
                    DateTime date;                
                    if(DateTime.TryParse(string.Format("{0}/{1}/{2}", (int) value, DateTime.Today.Day, DateTime.Today.Year), CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
                    {
                        CultureInfo culture = parameter != null ? new CultureInfo(parameter.ToString()) : CultureInfo.CurrentCulture;
                        return string.Format(culture, "{0:MMMM}", date);
                    }
                }
                return string.Empty;
            }
            catch (CultureNotFoundException e)
            {
                throw new ArgumentNullException("CultureInfo is not supported");    
            }
            catch(Exception e)
            {
                return string.Empty;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }
}
